package cn.edu.scau.cmi.linzhanyi.abstractFactory;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.layout.*;

import java.net.URL;
import java.util.Random;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.linzhanyi.abstractFactory.domainAbstractClass.Insurance;

public class Controller implements Initializable {

    @FXML
    private ComboBox<String> combox;
    @FXML
    private ComboBox<String> combox1;
    @FXML
    private TextArea showinfotext;
    @FXML
    private Pane pane;
    

    @FXML
    public void onbutton(){
    	String info = "保险公司：";
        AbstractFactory aFactory = AbstractFactory.getFactory(combox1.getSelectionModel().getSelectedItem().toString());
        Insurance insurance=null;
        switch (combox.getSelectionModel().getSelectedItem().toString()) {
			
			case "驾驶员身体受伤":insurance=aFactory.createBodyInsurance();break;
			case "汽车损坏" :insurance=aFactory.createCarInsurance();break;
			case "人员伤亡" :insurance=aFactory.createPeopleInsurance();break;
			case "多种事故" :insurance=aFactory.createMultipleAccidents();break;
		}
        
        info+=insurance.getCompany()+"\n保险介绍："+insurance.getIntroduction();
        
        
        pane.setStyle("-fx-background-image: url("+getClass().getResource((new Random().nextInt(2)+2)+""+".jpg")+"); -fx-background-repeat: no-repeat; -fx-background-size: stretch;");
        showinfotext.setText(info);

    }
    
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        pane.setStyle("-fx-background-image: url("+getClass().getResource((new Random().nextInt(2)+2)+""+".jpg")+"); -fx-background-repeat: no-repeat; -fx-background-size: stretch;");

        ObservableList<String> options =
                FXCollections.observableArrayList(
                        "驾驶员身体受伤","汽车损坏","人员伤亡","多种事故"
                );
        ObservableList<String> options2 =
                FXCollections.observableArrayList(
                        "中国人寿保险(PICC)","平安保险(PingAn)"
                );

       combox.setItems(options);
       combox.getSelectionModel().select(0);
       combox1.setItems(options2);
       combox1.getSelectionModel().select(0);


    }
}
